<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>
      <template #img="{ record }">
        <a-avatar shape="square">
          <img :src="record.img?record.img:'/nopic.png'" style="object-fit: cover" />
        </a-avatar>
      </template>

      <template #halation_img="{ record }">
        <a-avatar shape="square">
          <img :src="record.halation_img?record.halation_img:'/nopic.png'" style="object-fit: cover" />
        </a-avatar>
      </template>

      <template #bg_img="{ record }">
        <a-avatar shape="square">
          <img :src="record.bg_img?record.bg_img:'/nopic.png'" style="object-fit: cover" />
        </a-avatar>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import boxProductProbability from '@/api/box/boxProductProbability'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  boxProductProbability.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  boxProductProbability.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'box_product_probability',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: boxProductProbability.getList,
  recycleApi: boxProductProbability.getRecycleList,
  add: {
    show: true,
    api: boxProductProbability.save,
    auth: ['box:productProbability:save']
  },
  edit: {
    show: true,
    api: boxProductProbability.update,
    auth: ['box:productProbability:update']
  },
  delete: {
    show: true,
    api: boxProductProbability.deletes,
    auth: ['box:productProbability:delete'],
    realApi: boxProductProbability.realDeletes,
    realAuth: ['box:productProbability:realDeletes']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "风格名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入风格名称"
    }
  },
  {
    title: "颜色",
    dataIndex: "color",
    formType: "color-picker",
    commonRules: {
      required: true,
      message: "请输入风格名称"
    }
  },

  {
    title: "图片",
    dataIndex: "img",
    formType: "upload",
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "image"
  },
  {
    title: "晕影图片",
    dataIndex: "halation_img",
    formType: "upload",
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "image"
  },
  {
    title: "背景图片",
    dataIndex: "bg_img",
    formType: "upload",
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "image"
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    width:180,
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'box:productProbability' } </script>